import 'package:flutter/material.dart';
// import 'package:bottom_navigation_bar/bottom_navigation_bar.dart'; // 这个包名可能需要根据实际情况调整
import './ui/app_home_page.dart';
// import '../index/ui/new_class.dart';
import './setting_page.dart';
import '../models/tapdata.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage>
    with SingleTickerProviderStateMixin {
  // 将mixin移到这里

  // 当前索引值
  int _currentIndex = 0;

  // PageView控制器
  final _pageController = PageController(initialPage: 0);

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _pageController,
        onPageChanged: (index) {
          setState(() => _currentIndex = index);
        },
        children: [
          AppHomePage(), // 确保导入了这些页面
          // NewclassPage(),
          SettingsPage(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          _pageController.animateToPage(index,
              duration: const Duration(milliseconds: 300),
              curve: Curves.easeInOut);
          setState(() {
            _currentIndex = index;
          });
        },
        items: datas
            .map((data) => // 确保tapData已定义并正确导入
                BottomNavigationBarItem(
                  icon: Icon(
                    data.icon,
                    color:
                        _currentIndex == data.index ? Colors.red : Colors.grey,
                  ),
                  activeIcon: Icon(data.icon,
                      color: Colors.red), // 这里可以简化，因为active状态已经被上面的color控制了
                  label: data.title, // 使用label而不是单独设置title的style，除非你有特别的样式需求
                ))
            .toList(),
      ),
    );
  }
}
